#include<bits/stdc++.h>
using namespace std;
int a[100005],d[100005],v[100005],p[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--){
        int n,m,l,V,cnt=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];

        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&p[m]>=d[i])cnt++;
            }
        }
        if(cnt==0)cout<<cnt<<" "<<m<<endl;
        else cout<<cnt<<" "<<m-1<<endl;

    }

    return 0;
}
